import java.util.Scanner;

public class foodie {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        String[] foodlist = new String[]{"红烧带鱼", "鱼香肉丝", "时令鲜蔬"};
        double[] price = new double[]{38.0, 20.0, 10.0};
        //定义的菜品和对应的价格
        String[] user = new String[20]; //订餐人姓名
        String[] userfood = new String[20];//订的食品名称
        int[] foodnum = new int[20];  //食品数量
        int[] date = new int[20];   //送餐时间
        String[] address = new String[20]; //送餐地址
        double[] sum = new double[20];  //价格总计
        int[] fabulous = new int[3];//点赞数量
        boolean[] sign = new boolean[20];//签收控制信号
        for (int i = 0; i < sign.length; i++) {
            sign[i] = false;
        }//初始化签收控制信号为未签收
        for (int i = 0; i < fabulous.length; i++) {
            fabulous[i] = 0;
        }
        int start = 0;              //循环控制信号
        //测试数据 方便测试
        do {
            System.out.println("欢迎使用“吃货联盟订餐系统”");
            System.out.println("*******************************");
            System.out.println("1、我要订餐");
            System.out.println("2、查看餐袋");
            System.out.println("3、签收订单");
            System.out.println("4、删除订单");
            System.out.println("5、我要点赞");
            System.out.println("6、退出系统");
            System.out.println("*******************************");
            System.out.print("请选择：");
            switch (input.nextInt()) {
                case 1:
                    System.out.println("***我要订餐***");
                    System.out.print("请输入订餐人姓名：");
                    String name = input.next();                 //获取姓名
                    System.out.println("序号\t菜品\t单价");
                    for (int i = 0; i < foodlist.length; i++) {
                        System.out.println((i + 1) + "\t" + foodlist[i] + "\t" + price[i] + "元");
                    }
                    System.out.print("请输入您要点的菜品编号：");
                    int a = input.nextInt() - 1;               //获取菜品编号
                    System.out.print("请选择您需要的份数：");
                    int b = input.nextInt();                    //获取菜品份数
                    System.out.print("请输入送餐时间（送餐时间10点至20点整点）：");
                    int time = input.nextInt();              //获取送餐时间
                    if(time>=20||time<=10){
                        System.out.println("时间错误！请重新输入：");break;
                    }
                    System.out.print("请输入送餐地址：");
                    String add = input.next();                  //获取送餐地址
                    int tag = 0;
                    double cost=0;
                    for (int i = 0; i < user.length; i++) {
                        if (user[i] == null) {
                            user[i] = name;
                            userfood[i] = foodlist[a];  //把菜品编号对应的菜品存到userfood数组中
                            foodnum[i] = b;
                            date[i] = time;
                            address[i] = add;
                            sum[i] = price[a] * b;
                            tag = i;
                            break;
                        }
                    }
                    System.out.println("订餐成功！");
                    System.out.println("您订的是：" + userfood[tag] + " " + foodnum[tag] + "份");
                    System.out.println("送餐时间：" + date[tag]+"点");
                    if (sum[tag]<50){
                        cost=5;
                    }
                    System.out.println("餐费：" + sum[tag] + "元，送餐费"+cost+"元，总计：" + (sum[tag]+cost) + "元。");
                    System.out.print("输入0返回,输入其他退出：");
                    start = input.nextInt();
                    break;
                case 2:
                    if (user[0] == null) {
                        System.out.println("餐袋为空！");
                    } else {
                        System.out.println("***查看餐袋***");
                        System.out.println("序号  订餐人  餐品信息  送餐时间  送餐地址  总金额  订单状态");
                        for (int i = 0; i < user.length; i++) {
                            String sn = (sign[i] == false) ? "已预订" : "已完成";
                            if (user[i] != null) {
                                System.out.println((i + 1) + "   " + user[i] + "   " + userfood[i] + "  " + date[i] + "点  " + address[i] + "  " + sum[i] + "  " + sn);
                            }
                        }
                    }
                    System.out.print("输入0返回,输入其他退出：");
                    start = input.nextInt();
                    break;
                case 3:
                    if (user[0] == null) {
                        System.out.println("列表为空不能签收！");
                    } else {
                        System.out.println("***签收订单***");
                        System.out.println("请选择要签收的订单编号：");
                        System.out.println("序号\t订餐人\t餐品信息\t\t送餐时间\t\t送餐地址\t\t总金额\t订单状态");
                        for (int i = 0; i < user.length; i++) {
                            String sn = (sign[i] == false) ? "已预订" : "已完成";
                            if (user[i] != null) {
                                System.out.println((i + 1) + "\t\t" + user[i] + "\t" + userfood[i] + "\t\t" + date[i] + "\t" + address[i] + "\t\t" + sum[i] + "\t" + sn);
                            }
                        }
                        int num = input.nextInt() - 1;
                        sign[num] = true;
                        System.out.println("订单签收成功！");
                        System.out.println("序号\t订餐人\t餐品信息\t\t送餐时间\t\t送餐地址\t\t总金额\t订单状态");
                        for (int i = 0; i < user.length; i++) {
                            String sn = (sign[i] == false) ? "已预订" : "已完成";
                            if (user[i] != null) {
                                System.out.println((i + 1) + "\t\t" + user[i] + "\t" + userfood[i] + "\t\t" + date[i] + "\t" + address[i] + "\t\t" + sum[i] + "\t" + sn);
                            }
                        }
                        System.out.print("输入0返回,输入其他退出：");
                        start = input.nextInt();
                        break;
                    }
                case 4:
                    if (user[0] == null) {
                        System.out.println("列表为空不能删除！");
                    } else {
                        System.out.println("***删除订单***");
                        System.out.println("序号\t订餐人\t餐品信息\t\t送餐时间\t\t送餐地址\t\t总金额\t订单状态");
                        for (int i = 0; i < user.length; i++) {
                            String sn = (sign[i] == false) ? "已预订" : "已完成";
                            if (user[i] != null) {
                                System.out.println((i + 1) + "\t\t" + user[i] + "\t" + userfood[i] + "\t\t" + date[i] + "\t" + address[i] + "\t\t" + sum[i] + "\t" + sn);
                            }
                        }
                        System.out.print("请选择要删除的订单编号：");
                        int del = input.nextInt() - 1;
                        if (sign[del] == false) {
                            System.out.println("您选择的订单未签收，不能删除！");
                        } else {
                            user[del] = null;
                            userfood[del] = null;
                            foodnum[del] = 0;
                            date[del] = 0;
                            address[del] = null;
                            sum[del] = 0;
                            sign[del] = false;//清空，防止该位为数组最后一位
                            for (int K = del; K < user.length - 1; K++) {
                                user[K] = user[K + 1];
                                userfood[K] = userfood[K + 1];
                                foodnum[K] = foodnum[K + 1];
                                date[K] = date[K + 1];
                                address[K] = address[K + 1];
                                sum[K] = sum[K + 1];
                                sign[K] = sign[K + 1];
                                //从当前位的下一位开始，所有定义的变量全部前移一位
                            }
                            System.out.println("序号\t订餐人\t餐品信息\t\t送餐时间\t\t送餐地址\t\t总金额\t订单状态");
                            for (int i = 0; i < user.length; i++) {
                                String sn = (sign[i] == false) ? "已预订" : "已完成";
                                if (user[i] != null) {
                                    System.out.println((i + 1) + "\t\t" + user[i] + "\t" + userfood[i] + "\t\t" + date[i] + "\t" + address[i] + "\t\t" + sum[i] + "\t" + sn);
                                }
                            }
                        }
                    }
                    System.out.print("输入0返回,输入其他退出：");
                    start = input.nextInt();
                    break;
                case 5:
                    System.out.println("***我要点赞***");
                    System.out.println("序号\t 菜品\t\t单价\t\t点赞");
                    for (int i = 0; i < foodlist.length; i++) {
                        System.out.println((i + 1) + "\t\t" + foodlist[i] + "\t\t" + price[i] + "元" + "\t\t  " + fabulous[i]);
                    }
                    System.out.print("请选择您要点赞的菜品序号:");
                    int fab = input.nextInt() - 1;
                    fabulous[fab]++;
                    System.out.println("点赞成功！");
                    //冒泡排序
                    for (int i = 0; i < fabulous.length - 1; i++) {
                        for (int k = 0; k < fabulous.length - 1 - i; k++) {
                            if (fabulous[k] < fabulous[k + 1]) {
                                int tmp = fabulous[k];
                                fabulous[k] = fabulous[k + 1];
                                fabulous[k + 1] = tmp;
                                String s = foodlist[k];
                                foodlist[k] = foodlist[k + 1];
                                foodlist[k + 1] = s;
                                double m = price[k];
                                price[k] = price[k + 1];
                                price[k + 1] = m;
                            }
                        }
                    }
                    System.out.println("序号\t 菜品\t\t单价\t\t点赞");
                    for (int i = 0; i < foodlist.length; i++) {
                        System.out.println((i + 1) + "\t\t" + foodlist[i] + "\t\t" + price[i] + "元" + "\t\t  " + fabulous[i]);
                    }
                    System.out.print("输入0返回,输入其他退出：");
                    start = input.nextInt();
                    break;
                case 6:
                    System.out.println("欢迎使用，欢迎下次光临！");
                    start = 1;
            }
        } while (start == 0);
    }
}